package com.love.netty.core;

import com.alibaba.fastjson.JSON;
import com.love.netty.core.interfaces.Serializer;
import com.love.netty.core.interfaces.SerializerAlgorithm;

/**
 * @ClassName: JSONSerializer
 * @Description:
 * @Author: wuj
 * @Date: 2021-06-23 14:33
 **/
public class JSONSerializer implements Serializer {


    @Override
    public byte getSerializerAlgorithm() {

        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {

        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {

        return JSON.parseObject(bytes, clazz);
    }
}
